package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.hosp.service.IHospitalSetService;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.atguigu.yygh.param.hospSet.hospByIdParam;
import com.atguigu.yygh.param.hospSet.hospDeleteParam;
import com.atguigu.yygh.param.hospSet.hospStatusParam;
import com.atguigu.yygh.param.page.HospGetAllPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 医院设置表 前端控制器
 * </p>
 *
 * @author 方哥哥
 * @since 2022-03-14
 */
@RestController
@RequestMapping("/admin/hosp/hospital-set")
@Api(value = "HospitalSetController",tags = "医院设置管理")
public class HospitalSetController {
    @Resource
    private IHospitalSetService hospitalSetService;

    /**
     * 根据id获取医院设置
     */
    @ApiOperation(value = "根据id获取医院设置")
    @PostMapping("/getHospSet")
    public Result getHospSet(@RequestBody hospByIdParam param) {
        HospitalSet hospitalSet = hospitalSetService.getById(param.getId());
        return new Result(hospitalSet);
    }

    /**
     * 查询医院设置所有信息
     * @return
     */
    @ApiOperation(value = "获取所有医院设置")
    @GetMapping("/findAll")
    public Result findAllHospitalSet() {
        //调用service的方法
        List<HospitalSet> list = hospitalSetService.list();
        return new Result<>(list);
    }

    /**
     * 条件查询-分页
     * @param param
     * @return
     */
    @ApiOperation(value = "医院设置分页查询")
    @PostMapping("/findPageHospSet/")
    public Result findPageHospSet(@RequestBody HospGetAllPage param) {
        //返回结果
        return new Result<>("200",hospitalSetService.getPage(param));
    }

    /**
     * 逻辑删除医院设置
     * @param param
     * @return
     */
    @ApiOperation(value = "逻辑删除医院设置")
    @PostMapping("/delHosp/")
    public Result removeHospSet(@RequestBody hospDeleteParam param) {
        hospitalSetService.delectHosp(param);
        return new Result<>("200","删除医院信息成功");
    }

    /**
     * 添加或修改医院设置
     * @param hospitalSet
     * @return
     */
    @ApiOperation(value = "添加或修改医院设置")
    @PostMapping("/saveHospitalSet")
    public Result saveHospitalSet(@RequestBody HospitalSet hospitalSet) {
        hospitalSetService.saveHosp(hospitalSet);
        return new Result("200","操作成功！");
    }

    /**
     * 医院设置锁定和解锁
     */
    @ApiOperation(value = "医院设置锁定和解锁")
    @PostMapping("/lockHospitalSet")
    public Result lockHospitalSet(@RequestBody hospStatusParam param) {
        hospitalSetService.setHospStatus(param);
        return new Result("200","设置成功！");
    }

    /**
     * 发送签名秘钥
     */
    @ApiOperation(value = "发送签名秘钥")
    @PostMapping("/sendKey")
    public Result lockHospitalSent(@RequestBody hospByIdParam param) {
        hospitalSetService.sentlock(param);
        return new Result("200","发送签名秘钥成功！");
    }

}

